package log

import (
	"github.com/spf13/viper"
	"go.uber.org/zap"
	"log"
	"os"
	"sync"
)

var SievesLog *zap.Logger

func init() {
	viper.SetDefault("log.enable", true)
	viper.SetDefault("log.level", "info")
	viper.SetDefault("log.max_size", 5)
	viper.SetDefault("log.compress", false)
	viper.SetDefault("log.max_backups", 3)
	viper.SetDefault("log.max_age", "3")
	viper.SetDefault("log.name", "sieve")
	viper.SetDefault("log.path", "/var/log/")
}

func InitializeBaseLogEnvironment() {
	if os.Getenv("RUN_MODE") == "DAEMON" {
		err := redirect_std_log()
		if err != nil {
			log.Fatalf("redirect log failed,%s", err.Error())
		}
	}
}

func InitializeLogModule(flushChan chan int, syncer *sync.WaitGroup) {
	logger := CreateLogger(flushChan, "main")

	SievesLog = logger

	log.Println("initialize zaplog module finished")
}
